/*
package org.example.util;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import java.awt.*;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;

public class Test3 {

    public static void print(String content, String printerName) {
        if (content == null || content.isEmpty()) {
            throw new IllegalArgumentException("打印内容不能为空");
        }

        // 获取系统中的所有打印机
        PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
        PrintService selectedPrinter = null;

        // 遍历所有打印机并根据名称匹配
        for (PrintService printService : printServices) {
            if (printService.getName().equalsIgnoreCase(printerName)) {
                selectedPrinter = printService;
                break;
            }
        }

        if (selectedPrinter == null) {
            throw new IllegalArgumentException("找不到指定的打印机: " + printerName);
        }

        PrinterJob printerJob = PrinterJob.getPrinterJob();
        try {
            printerJob.setPrintService(selectedPrinter);
        } catch (PrinterException e) {
            throw new RuntimeException(e);
        }

        printerJob.setPrintable(new Printable() {
            @Override
            public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
                if (pageIndex >= 1) {
                    return Printable.NO_SUCH_PAGE;
                }
                Graphics2D g2d = (Graphics2D) graphics;
                g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
                g2d.setFont(new Font("Serif", Font.PLAIN, 12));
                g2d.drawString(content, 100, 100); // 在指定位置绘制文本
                return Printable.PAGE_EXISTS;
            }
        });

        boolean doPrint = printerJob.printDialog();
        if (doPrint) {
            try {
                printerJob.print();
            } catch (PrinterException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        // 测试打印内容，假设打印机名称为 "MyPrinter"
        String content = "这是发货单订单的内容！";
        String printerName = "HPRT N31C"; // 这里替换为你想选择的打印机名称
        //print(content, printerName);

        File fontFile = new File("C:\\Windows\\Fonts\\arialbd.ttf");

        // 验证字体文件是否存在
        if (!fontFile.exists()) {
            System.err.println("字体文件未找到: " + fontFile.getAbsolutePath());
            return;
        }
    }
}
*/
